/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jogs.client;

import java.io.BufferedReader;
import java.io.PrintStream;
import java.net.Socket;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.DefaultListModel;
//import javax.swing.text.StyledDocument;

/**
 *
 * @author Dactry
 */
public class TabInfo extends javax.swing.ImageIcon
{
  //public int index;
  protected ClientFrame parent;
  public JPanel backPanel;
  public JScrollPane backScrollPane;
  public JTextPane textPane;
  public Socket socket;
  public BufferedReader in;
  public PrintStream out;
  private DefaultListModel listModel;
  private String name;
  private JPanel oldPanel;
  private int ID;

  // 0 = not yet determined
  // 1 = lobby
  // 2 = room
  // 3 = table
  // 4 = table with game running (not yet implemented)
  public int type;

  public TabInfo(JPanel _backPanel, JScrollPane _backPane, JTextPane _textPane,
    Socket _socket, BufferedReader _in, PrintStream _out,
     ClientFrame _parent, int _type, String _name, int _ID)
  {
  	super();
    backPanel = _backPanel;
    backScrollPane = _backPane;
    textPane = _textPane;
    socket = _socket; in = _in; out = _out;
    //index = _index;
    parent = _parent;
    type = _type; 
    listModel = new DefaultListModel();
    name = _name;
    oldPanel = null;
    ID = _ID;
   }

  public void append(String line, String style)
  {
    parent.append(textPane, line, style);
    System.out.println(line);
  }

  public void disconnect()
  {
  	out.println("@DISC:");
  }
  
  public DefaultListModel getListModel()
  {
  	return listModel;
  }

  public void newGamePanel(JPanel newPanel)
  {
    oldPanel = backPanel;
    backPanel = newPanel;
    oldPanel.setVisible(false);
    newPanel.setVisible(true);
  }

  
  public void close()
  {
  	try
  	{
  		in.close();
  		out.close();
  		socket.close();
  		parent.closeTab(this);
  	}
  	catch(Exception e)
  	{
  		
  	}
  }
  
  
  public int getIndex()
  {
  	int r = -9999;
  	r = parent.getTabIndex(name);
  	return r;
  }
  
  public PrintStream getPrintStream(){return out;}
  
  public String getName() { return name; }
  
  public ClientFrame getParent() { return parent; }

  public int getID() {return ID;}
  
  public String getUsername() { return parent.getUsername(); }


}
